import { initState } from './state';
import { parseHtmlToRenderFunction } from './compiler';

export function initMixin(Vue) {
    Vue.prototype._init = function (options) {
        const vm = this;
        vm.$options = options;
        initState(vm);
        if(vm.$options.el) {
            vm.$mount(vm.$options.el);
        }
    }
    Vue.prototype.$mount = function (el) {
        const vm = this;
        if(!vm.render) {
            let template = vm.$options.template;
            if(!template && el) {
                el = document.querySelector(el);
                template = el.outerHTML;
            }
            vm.render = parseHtmlToRenderFunction(template);
        }
    }
}